<?php
/**
 * TomatoCMS
 *
 * LICENSE
 *
 * This source file is subject to the GNU GENERAL PUBLIC LICENSE Version 2
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.gnu.org/licenses/gpl-2.0.txt
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@tomatocms.com so we can send you a copy immediately.
 *
 * @copyright    Copyright (c) 2009-2010 TIG Corporation (http://www.tig.vn)
 * @license        http://www.gnu.org/licenses/gpl-2.0.txt GNU GENERAL PUBLIC LICENSE Version 2
 * @version     $Id: add.phtml 3032 2010-05-25 08:00:42Z huuphuoc $
 */
?>
<?php
$this->headTitle($this->translator('category_add_page_title'));
$this->headScript()
    ->appendFile($this->APP_STATIC_SERVER . '/js/jquery.validate/jquery.validate.min.js')
    ->appendFile($this->APP_STATIC_SERVER . '/js/tomato/util.js');
?>

<div class="grid_12 t_a_ui_breadcrumb">
    <span><a href="<?php echo $this->url(array(), 'shop_category_list'); ?>"><?php echo $this->translator('category_list_breadcump'); ?></a></span>
    <span><?php echo $this->translator('category_add_breadcrump'); ?></span>
</div>

<div class="grid_12"><?php echo $this->flashMessenger(); ?></div>

<form method="post" action="<?php echo $this->url(array(), 'shop_category_add'); ?>" id="addCategoryForm" class="t_a_form">
<div class="grid_12 t_a_bottom"><?php echo $this->translator('category_add_guide'); ?></div>

<div class="grid_12 t_a_bottom">
    <div class="prefix_1 suffix_1">
        <div class="clearfix t_a_bottom">
            <label><?php echo $this->translator('category_admin_name'); ?>:</label>
            <input maxlength="255" type="text" id="category_admin_name" name="category_admin_name" style="width: 300px" />
        </div>

        <hr />

        <div class="clearfix t_a_bottom">
            <label><?php echo $this->translator('category_status'); ?>:</label>
            <select id="category_status" name="category_status" style="width:170px">
                <option value="">---</option>
                <option value="1"><?php echo $this->translator('category_status_active'); ?></option>
                <option value="0"><?php echo $this->translator('category_status_inactive'); ?></option>
            </select>
        </div>

        <hr />

        <div class="clearfix t_a_bottom">
            <label><?php echo $this->translator('category_image'); ?>:</label>
            <?php
                /**
                * Allows user to browse uploaded file
                * @since 2.0.4
                */
                echo $this->browser('/upload/news/'.Zend_Auth::getInstance()->getIdentity()->user_name.'/'.date('Y').'/'.date('m'), 'jpg,gif,png', 'insertImage(%s)');
            ?>
        </div>

        <hr />

        <div class="clearfix t_a_bottom">
            <label>&nbsp;</label>
            <input type="checkbox" id="category_enable_product" name="category_enable_product" value="1" /> <?php echo $this->translator('category_enable_product'); ?>
        </div>

        <hr />

        <div class="clearfix t_a_bottom">
            <label><?php echo $this->translator('category_create_date'); ?>:</label>
            <?php echo $this->date;?>
        </div>

        <hr />

        <div class="clearfix t_a_bottom">
            <label><?php echo $this->translator('category_modify_date'); ?>:</label>
            <?php echo $this->date;?>
        </div>

        <hr />

        <div class="clearfix t_a_bottom">
            <label><?php echo $this->translator('category_parent'); ?>:</label>
            <select name="parentId" id="parentId" style="width:170px;">
                <option value="">---</option>
                <?php for ($i = 0; $i < count($this->categories); $i++) : ?>
                <option value="<?php echo $this->categories[$i]->category_id; ?>"><?php echo str_repeat('---', $this->categories[$i]->depth).$this->categories[$i]->category_admin_name; ?></option>
            <?php endfor; ?>
            </select>
        </div>

        <hr />

        <div class="clearfix t_a_bottom">
            <label>&nbsp;</label>
            <button type="submit"><span><?php echo $this->translator('category_add_save_button'); ?></span></button>&nbsp;&nbsp;&nbsp;
            <button type="reset"><span><?php echo $this->translator('category_reset_button'); ?></span></button>
        </div>
    </div>
</div>
</form>

<script type="text/javascript">

function insertImage(url) {
    tinyMCE.getInstanceById('content').execCommand('mceInsertContent', false, '<img src="' + url + '" />');
};

$(document).ready(function() {

    $('#addCategoryForm').validate({
        rules: {
            category_admin_name: {
                required: true,
                maxlength: 255
            },
            category_status:{
                required: true,
            }
        },
        messages: {
            category_admin_name: {
                required: "<?php echo $this->translator('category_name_required'); ?>",
                maxlength: "<?php echo $this->translator('category_name_maxlength'); ?>"
            },
            category_status: "<?php echo $this->translator('category_status_required'); ?>"
        }
    });
});
</script>
